package cn.cons;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.02.12.16.48
 */
public class Map1 {
    public static void main(String[] args) {
     map();
    }
    private static void map(){
        Map<Integer,String> m=new HashMap<>();
        m.put(1,"小黑");
        m.put(2,"小白");
        m.put(3,"小花");
        m.put(4,"小化");
        m.put(5,"小李");
        System.out.println(m.size());
        System.out.println(m.get(2));
        //map遍历
        Set<Map.Entry<Integer,String>> entry=m.entrySet();
        for (Map.Entry e:entry) {
            System.out.println("key="+e.getKey());
            System.out.println("value="+e.getKey());
        }
//遍历Keys
        Set<Integer> k=m.keySet();
        for (Integer ks:k) {
            System.out.println("key="+ks+",value="+m.get(ks));
        }
//遍历值
        Collection<String> v=m.values();
        for (String v1:v) {
            System.out.println(v1);

        }
    }
}
